<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>购物车</title>
    <link rel="stylesheet" href="../css/pc-ggys.css">
    <link rel="stylesheet" href="../css/cart.css">

</head>

<body>
    <div class="b_top">
        <div class="top">
            <div class="lf">
                <ul>
                    <li><a href="../html/06home.html">首页</a></li>
                    <li><a href="https://consumer.huawei.com/cn/" target="_blank">华为官网</a></li>
                    <li><a href="https://club.huawei.com" target="_blank">花粉俱乐部</a></li>
                    <li><a href="https://www.vmall.com/priority">V码(优购码)</a></li>
                    <li><a href="https://company.vmall.com/#/huawei" target="_blank">企业购</a></li>
                    <li><a href="">Select Region</a></li>
                    <li class="topdh">更多精彩
                        <div class="topejdh">
                            <div><a href="https://www.harmonyos.com/cn/home/" target="_blank">HarmonyOS</a></div>
                            <div><a href="https://appgallery.huawei.com/" target="_blank">应用市场</a></div>
                            <div><a href="https://cloud.huawei.com" target="_blank">华为终端云空间</a></div>
                            <div><a href="https://developer.huawei.com/consumer/cn/" target="_blank">开发者联盟</a></div>
                        </div>
                    </li>
                </ul>
            </div>
            <div class="ri">
                <ul>
                    <li>
                        <h1 class="loginIn">欢迎XX</h1>
                    </li>
                    <li><a class="loginOut">退出登录</a></li>
                    <li><a class="noLogin" href="../html/01login.html">请登录</a></li>
                    <li><a href="../html/02reg.html">注册</a></li>
                    <li><a href="">我的订单</a></li>
                    <li class="kfej">客服
                        <div class="kfejdh">
                            <div>
                                <a href="https://www.vmall.com/help/index.html" target="_blank">服务中心</a>
                            </div>
                            <div>
                                <a href="">联系客服</a>
                            </div>
                        </div>
                    </li>
                    <li><a href="">网站导航</a></li>
                    <li><a href="">手机版</a></li>
                    <li><a href="../html/05cart.html"><img class="gwctb" src="../img/gwc.png">购物车<span
                                class="nums">(0)</span></a></li>
                </ul>
            </div>
        </div>
    </div>
    <div class="b_mycar">
        <div class="mycar">
            <img id="hwimg"
                src="https://res4.vmallres.com/shopdc//pic/20211013/4f15c00a-24fc-4782-a825-5af7c9a98ae2.png" alt="">
            <p>我的购物车</p>
            <img id="hwgwc" src="../img/wdgwc.png" alt="">
        </div>
    </div>
    <div class="b_cart">
        <div class="cartbx">
            <h1 class="kts">您的购物车是空的，&nbsp;<a href="./06home.html">赶紧选购吧~</a></h1>
            <div class="catbox">
                <table>
                    <thead>
                        <tr>
                            <th><input type="checkbox" id="ckAll">全选</th>
                            <th>商品</th>
                            <th>名称</th>
                            <th>单价</th>
                            <th>数量</th>
                            <th>小计</th>
                            <th>操作</th>
                        </tr>
                    </thead>
                    <tbody class="tb">
                        <!-- <tr class="inline">
                    <td><input type="checkbox" name="ck"></td>
                    <td>Casio/卡西欧 EX-TR350</td>
                    <td>5999.88</td>
                    <td>
                        <span class="reduce">-</span>
                        <input type="text" value="1" class="count-input">
                        <span class="add">+</span>
                    </td>
                    <td>5999.88</td>
                    <td>
                        <span class="delete">删除</span>
                    </td>
                </tr> -->
                    </tbody>
                    <tfoot id="foot">
                        <tr>
                            <td class="del"><input class="delall" type="button" value="批量删除"></td>
                            <td></td>
                            <td></td>
                            <td></td>
                            <td>已选择<span id="allCount">0</span>件商品</td>
                            <td>总计：<span id="allPrice">0</span></td>
                            <td><button class="qjs">立即结算</button></td>
                        </tr>
                    </tfoot>
                </table>
                <div class="bewm">
                    <div class="ewm">
                        <img src="../img/ewmtp.jpg" alt="">
                        <h3>请扫码付款</h3>
                        <h4 class="jg">商品总价：</h4>
                        <p>点击窗口外关闭</p>
                    </div>
                </div>
            </div>
        </div>
    </div>
    <footer>
        <div class="fot_s">
            <div class="fot_sz">
                <ul class="s1">
                    <p class="title">
                        购物指南
                    </p>
                    <li>
                        <a target="_blank" href="https://www.vmall.com/help/faq-4359.html" rel="nofollow">免息分期</a>
                    </li>
                    <li>
                        <a target="_blank" href="https://www.vmall.com/help/faq-7923.html" rel="nofollow">以旧换新</a>
                    </li>
                    <li>
                        <a target="_blank" href="https://www.vmall.com/help/faq-13022.html" rel="nofollow">众测活动</a>
                    </li>
                    <li>
                        <a target="_blank" href="https://www.vmall.com/help/faq-9295.html" rel="nofollow">企业购</a>
                    </li>
                    <li>
                        <a target="_blank" href="https://www.vmall.com/help/faq-13020.html" rel="nofollow">O2O采购</a>
                    </li>
                </ul>
                <ul class="s1">
                    <p class="title">
                        售后服务
                    </p>
                    <li>
                        <a target="_blank" href="https://www.vmall.com/help/faq-16708.html" rel="nofollow">门店维修</a>
                    </li>
                    <li>
                        <a target="_blank" href="https://consumer.huawei.com/cn/support/warranty-policy/"
                            rel="nofollow">保修政策</a>
                    </li>
                    <li>
                        <a target="_blank" href="https://www.vmall.com/help/faq-16682.html" rel="nofollow">防伪查询</a>
                    </li>
                    <li>
                        <a target="_blank" href="https://www.vmall.com/help/faq-834.html" rel="nofollow">退换货政策</a>
                    </li>
                    <li>
                        <a target="_blank" href="https://www.vmall.com/help/faq-16698.html" rel="nofollow">手机寄修服务</a>
                    </li>
                    <li>
                        <a target="_blank" href="https://www.vmall.com/help/faq-16706.html" rel="nofollow">维修备件价格查询</a>
                    </li>
                </ul>
                <ul class="s1">
                    <p class="title">
                        维修与技术支持
                    </p>
                    <li>
                        <a target="_blank" href="https://consumer.huawei.com/cn/support/service-center/index.htm"
                            rel="nofollow">服务店</a>
                    </li>
                    <li>
                        <a target="_blank" href="https://consumer.huawei.com/cn/support/reservation/index.htm"
                            rel="nofollow">预约维修</a>
                    </li>
                    <li>
                        <a target="_blank" href="https://consumer.huawei.com/cn/support/express-repair/index.htm"
                            rel="nofollow">手机寄修</a>
                    </li>
                    <li>
                        <a target="_blank" href="https://consumer.huawei.com/cn/support/sparepart-price/index.htm"
                            rel="nofollow">备件价格查询</a>
                    </li>
                    <li>
                        <a target="_blank" href="https://consumer.huawei.com/cn/support/door-to-door-service/"
                            rel="nofollow">上门服务</a>
                    </li>
                </ul>
                <ul class="s1">
                    <p class="title">
                        特色服务
                    </p>
                    <li>
                        <a target="_blank" href="https://consumer.huawei.com/cn/support/discriminate/"
                            rel="nofollow">防伪查询</a>
                    </li>
                    <li>
                        <a target="_blank" href="https://www.vmall.com/member/buyServicesIndex" rel="nofollow">补购保障</a>
                    </li>
                    <li>
                        <a target="_blank" href="https://www.vmall.com/recycler" rel="nofollow">以旧换新</a>
                    </li>
                    <li>
                        <a target="_blank" href="https://www.vmall.com/product/10086344499475.html#10086230774569"
                            rel="nofollow">礼品包装</a>
                    </li>
                </ul>
                <ul class="s1">
                    <p class="title">
                        关于我们
                    </p>
                    <li>
                        <a target="_blank" href="https://www.huawei.com/cn/about-huawei/corporate-information"
                            rel="nofollow">公司介绍</a>
                    </li>
                    <li>
                        <a target="_blank" href="https://consumer.huawei.com/cn/support/where-to-buy"
                            rel="nofollow">华为零售店</a>
                    </li>
                    <li>
                        <a target="_blank" href="https://www.vmall.com/huawei/bophome.html" rel="nofollow">商家中心</a>
                    </li>
                    <li>
                        <a href="javascript:;" class="js-feedback" title="意见反馈">意见反馈</a>
                    </li>
                </ul>
                <ul class="s1">
                    <p class="title">友情链接</p>
                    <li>
                        <a href="https://www.huawei.com/cn" target="_blank" rel="noopener">华为集团</a>
                    </li>
                    <li>
                        <a href="https://consumer.huawei.com/cn" target="_blank" rel="noopener">华为CBG官网</a>
                    </li>
                    <li>
                        <a href="https://club.huawei.com" target="_blank" rel="noopener">花粉俱乐部</a>
                    </li>
                    <li>
                        <a href="https://www.huaweicloud.com" target="_blank" rel="noopener">华为云</a>
                    </li>
                    <li>
                        <a href="https://appgallery.huawei.com/" target="_blank" rel="noopener">华为应用市场</a>
                    </li>
                    <li>
                        <a href="https://xinsheng.huawei.com/cn/index" target="_blank" rel="noopener">华为心声社区</a>
                    </li>
                </ul>
            </div>
            <div class="fot_xian"></div>
            <div class="fot_sy">
                <h4>950805</h4>
                <p>7 x 24 小时客服热线 (仅收市话费)</p>
                <div class="zxkf"><a href=""><img src="../img/kf.png" alt="">在线客服</a></div>
                <div class="zxkftp">
                    <h2>关注VMALL:</h2>
                    <a class="awx" href=""><img src="../img/wx.png" alt="">
                        <div class="wxewm"><img
                                src="https://res.vmallres.com/pimages//pages/cdnImages/66357398344619375366.jpg" alt="">
                        </div>
                    </a>
                    <a href="https://www.toutiao.com/c/user/token/MS4wLjABAAAAs8rht0TsBhARnVJBDm-irbJ_rFdayHddfMoxtv40ZDw/?#mid=52586950033"
                        target="_blank"><img src="../img/totiao.png" alt=""></a>
                    <a href="https://weibo.com/shophuawei" target="_blank"><img src="../img/wb.png" alt=""></a>
                    <a href="https://author.baidu.com/home/1587993495688621" target="_blank"><img src="../img/bd.png"
                            alt=""></a>
                </div>
            </div>
        </div>
        <div class="fot_x">
            <p class="hwsc"><a href="https://www.vmall.com"><img
                        src="https://res.vmallres.com/pimages//pages/cdnImages/33223073294617032233.png"
                        title="华为商城"></a></p>
            <div class="fl">
                <ul class="ftul">
                    <li>
                        <a href="https://www.huawei.com/cn/">华为集团</a>
                    </li>
                    <li>
                        <a href="https://consumer.huawei.com/cn/">华为CBG官网</a>
                    </li>
                    <li>
                        <a href="https://club.huawei.com/">花粉俱乐部</a>
                    </li>
                    <li>
                        <a href="https://appgallery.huawei.com/">华为应用市场</a>
                    </li>
                    <li>
                        <a href="https://www.harmonyos.com/">HarmonyOS</a>
                    </li>
                    <li>
                        <a href="https://cloud.huawei.com">华为终端云空间</a>
                    </li>
                    <li>
                        <a href="https://developer.huawei.com/cn/">开发者联盟</a>
                    </li>
                    <li>
                        <a href="https://m.vmall.com/app/open?type=1">华为商城手机版</a>
                    </li>
                </ul><a
                    href="https://privacy.consumer.huawei.com/legal/vmall/privacy-statement.htm?code=CN&amp;branchid=0&amp;language=zh-cn&amp;contenttag=default"
                    rel="nofollow" target="_blank" title="隐私声明">隐私声明</a> <a
                    href="https://privacy.consumer.huawei.com/legal/vmall/terms.htm?code=CN&amp;branchid=0&amp;language=zh-cn&amp;contenttag=default"
                    rel="nofollow" target="_blank" title="服务协议">服务协议</a> <a href="https://msale.vmall.com/cookies.html"
                    rel="nofollow" target="_blank" title="COOKIES">COOKIES</a> Copyright © 2012-<span
                    id="j-copyrightyear">2022</span>
                华为终端有限公司 版权所有 <a href="https://www.vmall.com/notice-17426" target="_blank">| 经营资质 |</a><a
                    href="https://beian.miit.gov.cn/" target="_blank"> 粤ICP备19015064号</a><em>|</em><a
                    href="http://www.beian.gov.cn/portal/registerSystemInfo?recordcode=44190002003939"
                    target="_blank">粤公网安备 44190002003939号</a><br><a target="_blank"
                    href="https://res.vmallres.com/pimages//pages/cdnImages/40227551365615572204.png">增值电信业务经营许可证：粤B2-20190762<em>|</em></a><a
                    target="_blank"
                    href="https://wxdxsba.miit.gov.cn/serviceAction.action">备案主体编号：44201919072182</a><em>|</em><a
                    target="_blank"
                    href="https://res.vmallres.com/pimages//pages/cdnImages/91133651365615633119.pdf">粤新出网备（2021）2号<em>|</em></a><a
                    target="_blank"
                    href="https://res.vmallres.com/pimages//pages/cdnImages/58220651365615602285.png">（粤）网械平台备字[2022]第00005号<br></a><a
                    target="_blank"
                    href="https://res.vmallres.com/pimages//pages/cdnImages/17308188080618180371.jpg">互联网药品信息服务资格证（粤）-非经营性-2020-0102</a>
                | <a target="_blank"
                    href="https://res.vmallres.com/pimages//pages/cdnImages/29005784435618750092.pdf">粤东食药监械经营备20203930</a>
                | <a target="_blank"
                    href="https://res.vmallres.com/pimages//pages/cdnImages/42579551365615597524.png">广东省网络食品交易第三方平台备案：GDWS10168</a>
            </div>
            <p class="dzzp"><a href="https://res3.vmallres.com/shopdc/pic/5a818c14-f886-41b6-ad48-56c94a430471.jpg"><img
                        src="https://res.vmallres.com/pimages/template/content/2016/20160226162415360.png" alt=""></a>
            </p>
        </div>
    </footer>



    <script src="../js/promise_ajax.js"></script>
    <script src="../js/api.js"></script>
    <script>
        //获取二维码的爹
        const oBewm = document.querySelector('.bewm')
        console.log(oBewm);
        //获取二维码盒子
        const oEwm = document.querySelector('.ewm')
        console.log(oEwm);
        //获取结算按钮
        const oQjs = document.querySelector('.qjs')
        console.log(oQjs);
        //获取购物车为空提示
        const oKts = document.querySelector('.kts')
        console.log(oKts);

        // 首先判断是否登录
        const username = localStorage.getItem('LOGIN_USER');
        console.log(username);


        const oTb = document.querySelector('.tb');
        const oCatbox = document.querySelector('.catbox');
        // console.log(oCatbox);
        // 所有的单选
        const oOnes = document.getElementsByName("ck");
        console.log(oOnes);
        // 全选
        const oAll = document.getElementById('ckAll');
        // console.log(oAll);

        //获取总数
        const oDigit = document.getElementById('allCount');
        console.log(oDigit);
        //获取总价
        const oM = document.getElementById('allPrice');
        console.log(oM);


        // 登录状态 欢迎谁？
        const oH1 = document.querySelector('.loginIn');
        // const username = localStorage.getItem('LOGIN_USER');

        // 判断是否登录  localStorage   LOGIN_USER
        const oLoginIn = document.querySelector(".loginIn");
        const oNoLogin = document.querySelector(".noLogin");
        const oLoginOutBtn = document.querySelector('.loginOut');
        const oNums = document.querySelector('.nums');
        console.log(oNums.innerHTML);
        //如果有用户名说明登录了 欢迎出现 退出登录出现
        if (username) {
            oH1.style.display = 'block';
            oH1.innerHTML = '欢迎' + username;
            oLoginOutBtn.style.display = 'block';
            //没有说明 未登录  登录注册出现 退出登录消失
        } else {
            oNoLogin.style.display = 'block';
            oLoginOutBtn.style.display = 'none';

        }
        // 退出登录   清除localStorage    跳转至登录页面

        oLoginOutBtn.onclick = function () {
            // 清除localStorage
            localStorage.removeItem('LOGIN_USER');
            // 跳转至登录页面
            location.href = './01login.html';
        }


        getCart()
        async function getCart() {
            if (username) {
                await showCart({
                    username
                }).then(data => {
                    console.log(data);
                    // 判断是否有数据
                    if (!data.status) {
                        // 购物车不显示
                        oCatbox.style.display = 'none';
                        // alert('购物车空空如也，请去逛逛吧！');
                        // location.href = './003列表.html';
                        oKts.style.display = 'block';
                        return;
                    }
                    let html = '';
                    let spid = 0;
                    const { list } = data;
                    console.log(list);
                    list.forEach(({
                        num,
                        name,
                        img,
                        price,
                        goods_id,
                        cart_id
                    }) => {
                        spid++;
                        html += `
                            <tr class="inline" cart-id="${cart_id}">
                                <td><input type="checkbox" name="ck"></td>
                                <td><img src="${img}" alt=""></td>
                                <td>${name}</td>
                                <td>${price}</td>
                                <td  class="txh">
                                    <span class="reduce" goods-id="${goods_id}">${num > 1 ? '-' : ''}</span>
                                    <input type="text" value="${num}" class="count-input" goods-id="${goods_id}">
                                    <span class="add" goods-id="${goods_id}">+</span>
                                </td>
                                <td>${price * num}</td>
                                <td>
                                    <span class="delete" goods-id="${goods_id}">删除</span>
                                </td>
                            </tr>
                        `
                    })

                    oTb.innerHTML = html;
                    oNums.innerHTML = '(' + spid + ')';

                })
                // await showCart({
                //     username
                // }).then(data => {
                //     console.log(data);
                //     let spid = 0;
                //     data.list.forEach(({ goods_id }) => {
                //         spid++
                //     })
                //     oNums.innerHTML = '(' + spid + ')';
                // })

            } else {
                alert('请登录');
                // 跳转到登录 把当前页面的地址携带上
                location.href = './01login.html?WZA=' + location.href;
            }
        }


        //事件委托
        oCatbox.onclick = async function (e) {
            const target = e.target;


            // 数量加
            //    访问加入购物车的接口  addToCart (username / num / id)
            //    商品id可以绑定在标签上(自定义属性goods-id)
            if (target.className === 'add') {
                const id = target.getAttribute('goods-id');
                await addToCart({
                    username,
                    num: 1,
                    id
                }).then(data => {
                    console.log(data);
                    const { status } = data;
                    if (status) {
                        target.previousElementSibling.value++;
                        target.previousElementSibling.previousElementSibling.innerHTML;
                        if (target.previousElementSibling.previousElementSibling.innerHTML === '') {
                            //添加加号
                            target.previousElementSibling.previousElementSibling.innerHTML = '-'
                        }
                        //小计=数量*单价
                        target.parentElement.nextElementSibling.innerHTML = target.previousElementSibling.value * target.parentElement.previousElementSibling.innerHTML;
                        sum();
                    }
                })
            }

            // 数量框
            // 失去焦点后判断
            if (target.className === 'count-input') {
                const id = target.getAttribute('goods-id');
                console.log(id);
                console.log(778);
                var qjname = target.value;
                target.onchange = function () {
                    var name = target.value;
                    if (name === '') {
                        alert('请输入内容')
                    }
                    if (name < 1 || name % 1 != 0) {
                        alert('请输人正整数');
                        target.value = qjname;
                    }
                    let sl=name-qjname;
                    console.log(sl);
                    //小计=数量*单价
                    
                   
                    addToCart({
                        username,
                        num: sl,
                        id
                    }).then(data => {
                        console.log(data);
                        const { status } = data;
                        if (status) {

                            if (target.previousElementSibling.innerHTML === '') {
                                //添加加号
                                target.previousElementSibling.innerHTML = '-';
                            }
                            if (target.value === '1') {
                                //添加加号
                                target.previousElementSibling.innerHTML = '';
                            }
                            //小计=数量*单价
                            target.parentElement.nextElementSibling.innerHTML = target.value * target.parentElement.previousElementSibling.innerHTML;
                            sum();
                        }
                    })
                }
                ////

            }

            // 减号   num变成-1
            if (target.className === 'reduce') {
                const id = target.getAttribute('goods-id');
                if (target.nextElementSibling.value > 1) {
                    await addToCart({
                        username,
                        num: -1,
                        id
                    }).then(data => {
                        console.log(data);
                        const { status } = data;
                        if (status) {
                            target.nextElementSibling.value--;
                            //小计=数量*单价
                            target.parentElement.nextElementSibling.innerHTML = target.nextElementSibling.value * target.parentElement.previousElementSibling.innerHTML;
                            sum();
                            if (target.nextElementSibling.value == 1) {
                                target.innerHTML = ''
                            }
                        }
                    })
                } else {
                    alert('再减就没有了 亲！')
                }
            }


            //全选
            if (target.id === 'ckAll') {
                // console.log(454);
                oOnes.forEach(function (v) {
                    v.checked = target.checked;
                })
                sum();
                return;
            }


            //反选
            if (target.name === 'ck') {
                console.log(778);
                for (var i = 0; i < oOnes.length; i++) {
                    if (!oOnes[i].checked) {
                        break;
                    }
                }
                oAll.checked = (i === oOnes.length);
                sum();
            }


            //单删
            // 获取全部单删
            const oDels = document.querySelectorAll('.delete');
            // console.log(oDels);
            if (target.className === 'delete') {
                // const id = target.getAttribute('goods-id');
                const id = target.parentElement.parentElement.getAttribute('cart-id');

                await delete1({
                    username,
                    id
                }).then(data => {
                    console.log(data);
                    const { status, msg } = data;
                    if (status) {
                        target.parentElement.parentElement.remove();
                        //重新获取删除后剩下的单选
                        const oOnes = document.getElementsByName("ck");
                        //bug修复 判断剩下的单选状态决定多选
                        var flag = true
                        oOnes.forEach(function (v) {
                            if (!v.checked) {
                                flag = false;
                            }
                        })
                        oAll.checked = flag;
                        // 如果没有长度就是0 全选框就没有checked属性
                        if (oOnes.length === 0) {
                            oAll.checked = !oAll.checked;
                        }
                        // 判断数据是不是删完了？？？？？？？？？？？
                        // 如果没有子元素就判断
                        if (oTb.children.length === 0) {
                            // alert('单删的空空如也');
                            // location.href = './003列表.html';
                            oCatbox.style.display = 'none';
                            oKts.style.display = 'block';
                        }
                    } else {
                        alert(msg);
                    }
                    sum();
                })
                await showCart({
                    username
                }).then(data => {
                    console.log(data);
                    if (data.msg === "数据库错误") {
                        console.log(data.msg);
                        oNums.innerHTML = '(' + 0 + ')';
                    } else {
                        let spid = 0;
                        data.list.forEach(({ goods_id }) => {
                            spid++
                        })
                        oNums.innerHTML = '(' + spid + ')';
                    }
                })

                return;
            }


            //全删
            if (target.className === 'delall') {
                // 判断是否勾选
                const oOnes = document.getElementsByName("ck");
                console.log(oOnes);
                oOnes.forEach(v => {
                    // 判断是否勾选
                    if (v.checked) {
                        // 获取tr身上的自定义属性
                        const id = v.parentElement.parentElement.getAttribute('cart-id');
                        // 先删除页面()
                        // v.parentElement.parentElement.remove() ;
                        // 判断数据是不是删完了？？？？？？？？？？？

                        //再删数据库
                        delete1({
                            id
                        }).then(data => {
                            console.log(data);
                            const { status, msg } = data;
                            if (status) {
                                v.parentElement.parentElement.remove();
                                // 判断数据是不是删完了？
                                if (oTb.children.length === 0) {
                                    // alert('全删的空空如也');
                                    // location.href = './003列表.html';
                                    oCatbox.style.display = 'none';
                                    oKts.style.display = 'block';
                                }
                                sum();
                            } else {
                                alert(msg);
                            }
                        })
                    }//
                })
                // 重新获取删除后的单选框
                const oOnes1 = document.getElementsByName("ck")
                // 如果没有长度就是0 全选框就没有checked属性
                if (oOnes1.length === 0) {
                    oAll.checked = !oAll.checked;
                }
                showCart({
                    username
                }).then(data => {
                    console.log(data);
                    if (data.msg === "数据库错误") {
                        console.log(data.msg);
                        oNums.innerHTML = '(' + 0 + ')';
                    } else {
                        let spid = 0;
                        data.list.forEach(({ goods_id }) => {
                            spid++
                        })
                        oNums.innerHTML = '(' + spid + ')';
                    }
                })
            }

            //结算
            if (target.className === 'qjs') {
                //如果单价大于0才能出现二维码
                if (target.parentElement.previousElementSibling.children[0].innerHTML > 0) {
                    const oJg = document.querySelector('.jg');
                    oJg.innerHTML = '商品总价：￥' + target.parentElement.previousElementSibling.children[0].innerHTML;
                    oBewm.style.display = 'block';
                    oEwm.style.display = 'block';
                }
                else {
                    alert('请先选择商品')
                }
            }

            //二维码他爹
            if (target.className === 'bewm') {
                oBewm.style.display = 'none';
            }


            ////////
        }





        //   封装求和函数
        function sum() {
            var res = 0;  // 数量
            var money = 0;//总价
            const oOnes = document.getElementsByName("ck");
            //判断单选框的状态 先遍历
            for (i = 0; i < oOnes.length; i++) {
                //判断选中的执行
                if (oOnes[i].checked) {
                    // 找到数量的值
                    var count = oOnes[i].parentElement.nextElementSibling.nextElementSibling.nextElementSibling.nextElementSibling.children[1].value;
                    res += count * 1;
                    //找到小计的值
                    money += oOnes[i].parentElement.nextElementSibling.nextElementSibling.nextElementSibling.nextElementSibling.nextElementSibling.innerHTML * 1;
                }
            }
            oDigit.innerHTML = res;
            oM.innerHTML = money.toFixed(1);
        }


    </script>



</body>


</html>